package cpr.context.ruleacceptor;

import cpr.Rule;
import cpr.context.CacheRuleContext;
import cpr.context.Context;
import cpr.data.HLVector;

public class SearchRuleAcceptor implements IRuleAcceptor {
	String searchString;
	int ruleNr;
	int ruleNrGlobal;
	Context ctx;
	HLVector aVector;
	
	public SearchRuleAcceptor(Context ctx, String searchString, HLVector vector) {
		this.searchString = searchString.trim();
		this.ruleNr = 0;
		this.ruleNrGlobal = 0;
		this.ctx = ctx;
		this.aVector = vector;
	}
	
	
	public int nextRuleGlobalNr() {
		int t = ruleNrGlobal;
		ruleNrGlobal++;
		return t;
	}
	public boolean acceptGlobalNr(int globalNr) {
		return true;
	}
	public boolean accept(Rule aRule, int globalNr) {
		aRule.ruleNrGlobal = globalNr;
		String aString = ctx.getPrintContext().printRuleUsingDict(aRule, aVector).trim();
		if (searchString.equals(aString)) {
			aRule.ruleNr = ruleNr;
			ruleNr++;
			return true;
		} else {
			return false;
		}
	}
	
}
